package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.vo.BorrowInfoApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoDetailVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoSearchVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoVO;
import com.atguigu.srb.core.service.BorrowInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-03-25
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {
    @Resource
    BorrowInfoService borrowInfoService;

    @ApiOperation("借款审批")
    @PutMapping("approval")
    public ResponseVo approval(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO){
        borrowInfoService.approval(borrowInfoApprovalVO);
        return ResponseVo.ok();
    }
    @ApiOperation("查询借款详情")
    @GetMapping("{id}")
    public ResponseVo borrowInfoDetail(@PathVariable("id")Long id){
        BorrowInfoDetailVO borrowInfoDetailVO = borrowInfoService.getBorrowInfoDetail(id);
        return ResponseVo.ok().data("item",borrowInfoDetailVO);
    }
    // 姓名手机号模糊查询、借款金额区间查询、借款期限区间查询、还款方式、资金用途、状态、时间区间查询
    @ApiOperation("查询借款列表")
    @GetMapping("{pageNum}/{pageSize}") //pojo  axios提交对象通过params
    public ResponseVo list(BorrowInfoSearchVO borrowInfoSearchVO,
                           @PathVariable("pageNum")Integer pageNum,
                           @PathVariable("pageSize")Integer pageSize){ //接收前端提交的条件

        Page<BorrowInfoVO> page = borrowInfoService.getBorrowInfoVOs2(borrowInfoSearchVO,
                pageNum,pageSize);
        //因为借款列表页 需要的数据 没有合适的bean可以映射  需要自定义vo类
        return ResponseVo.ok().data("page",page);
    }

}

